package c_leetcode.a_1_tow_sum;

import java.util.Arrays;

/**
 * 遍历
 * 时间复杂度    O(n^2)
 * 空间复杂度    O(1)
 *
 * @author FRSF
 * @since 2025/2/23 13:41
 */
public class Foreach {

    public static void main(String[] args) {
        int[] nums = {2, 7, 11, 15};
        int target = 9;
        Foreach forEach = new Foreach();
        System.out.println(Arrays.toString(forEach.twoSum(nums, target)));
    }

    public int[] twoSum(int[] nums, int target) {
        for (int i = 0; i < nums.length - 1; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                if (target == nums[i] + nums[j]) {
                    return new int[]{i, j};
                }
            }
        }
        return new int[0];
    }
}
